<template>
<div>

<el-form class="mt10" :model="productDetail" label-width="180px">

		<el-form-item label="类别：" >
			<el-select v-model="productDetail.type_code" filterable >
			    <el-option
			      v-for="item in tlist"
			      :label="item.type_name"
			      :value="item.type_code">
			    </el-option>
			</el-select>

			<el-button @click="saveType">设置</el-button>

		</el-form-item>


		<el-form-item label="栏目：" >
			<el-select v-model="productDetail.column_code" filterable >
			    <el-option
			      v-for="item in clist"
			      :label="item.column_name"
			      :value="item.column_code">
			    </el-option>
			</el-select>

			<el-button @click="saveColumn">设置</el-button>
		</el-form-item>

</el-form>

</div>
</template>

<script>

import { mapGetters } from 'vuex'

export default {
	
	name : 'productother',
	
	data () {
		return {
		  	// form : {
		  	// 	type : '0',
		  	// 	column : '0',
		  	// }
		}
	},

	props : {
		productDetail : Object,
	},

	components : {
		
	},

	computed : {
		...mapGetters([
			'typeList',
			'columnList',
		]),

		tlist () {
			this.typeList.unshift({ type_name : '未设置类别', type_code: '0' });
			return this.typeList;
		},

		clist () {
			this.columnList.unshift({ column_name : '未设置栏目', column_code: '0' });
			return this.columnList;
		},
	},

	methods : {
		saveType () {
			const para = {
				fun : 'updateProduct',
				id : this.productDetail.id,
				sale_code : this.productDetail.sale_code,
				type_code : this.productDetail.type_code,
				cb : res => {
					this.$notify({
			          title: '成功',
			          message: '保存成功',
			          type: 'success'
			        });
				},
				err : res => {
					this.$notify({
			          title: '保存失败',
			          message: res,
			          type: 'error'
			        });
				}
			};

			this.$store.dispatch('update', para);
		},

		saveColumn () {
			const para = {
				fun : 'updateProduct',
				id : this.productDetail.id,
				sale_code : this.productDetail.sale_code,
				column_code : this.productDetail.column_code,
				cb : res => {
					this.$notify({
			          title: '成功',
			          message: '保存成功',
			          type: 'success'
			        });
				},
				err : res => {
					this.$notify({
			          title: '保存失败',
			          message: res,
			          type: 'error'
			        });
				}
			};

			this.$store.dispatch('update', para);
		},
	},

	watch : {
	    
	},

	mounted () {
		this.$store.dispatch('getTypeList');
		this.$store.dispatch('getColumnList');
	},

}
</script>

<style scoped>

</style>
